A = double(imread('cameraman.tif'));
figure,imshow(imread('cameraman.tif')),title('Original Image');
[m,n] = size(A);
B = zeros(size(A));
[u s v] = svd(A);
k = input('Enter the number of components ');
for i = 1:k
   B = B +(s(i,i)*u(:,i)*v(:,i).'); 
end
cr = m*n/(k*(m+n+1));
disp(['Compression Ratio is : ',num2str(cr)]);
figure,imshow(uint8(B)),title('Compressed Image');
